Adding some more judges, here and there.
[and.git] / Maratones competidas / Maratón Nacional 2011 / workspace / e / e.cpp
blobb1367124fa1da0eb24069045509feac568fb9084
1 // Equipo Poncho, Carriel y Ruana
2 using namespace std;
3 #include <algorithm>
4 #include <iostream>
5 #include <iterator>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <stack>
18 #include <list>
19 #include <map>
20 #include <set>
22 template <class T> string toStr(const T &x)
23 { stringstream s; s << x; return s.str(); }
24 template <class T> int toInt(const T &x)
25 { stringstream s; s << x; int r; s >> r; return r; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS = 1e-9;
33 int cmp(double x, double y = 0, double tol = EPS) {
34 return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
37 #define INPUT_FILE "edgetown"
39 const int MAXN = 105;
40 const int oo = 1<<28;
42 int g1[MAXN][MAXN];
43 int g2[MAXN][MAXN];
44 int n;
46 void floyd(){
47 For(k, 0, n) {
48 For(i, 0, n) {
49 For(j, 0, n) {
50 g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);
51 g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
57 bool equal(long long a, long long b) {
58 For(i, 0, n) {
59 For(j, 0, n) {
60 if (g2[i][j] >= oo) return false;
61 long long now = g2[i][j];
62 long long cota = g1[i][j] * a + b;
63 if (now > cota) {
64 //printf("From %d to %d: now = %d, cota = %d, old = %d\n", i, j, (int)now, (int)cota, g1[i][j]);
65 return false;
69 return true;
72 int main(){
73 freopen(INPUT_FILE ".in", "r", stdin);
74 while (cin >> n) {
75 if (n == 0) break;
76 string s; getline(cin, s);
78 For (i, 0, n) For(j, 0, n) g1[i][j] = g2[i][j] = oo;
80 for (int i = 0; i < n; ++i) {
81 getline(cin, s);
82 stringstream sin(s);
83 int first; sin >> first; first--;
84 int other;
85 while (sin >> other) {
86 other--;
87 g1[first][other] = 1;
91 for (int i = 0; i < n; ++i) {
92 getline(cin, s);
93 stringstream sin(s);
94 int first; sin >> first; first--;
95 int other;
96 while (sin >> other) {
97 other--;
98 g2[first][other] = 1;
101 For(i, 0, n) g1[i][i] = g2[i][i] = 0;
103 int a, b;
104 cin >> a >> b;
105 if (a == 0 and b == 0 and n > 1) {
106 puts("No");
107 continue;
110 //puts("G1"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g1[i][j]); } puts(""); } puts("");
111 //puts("G2"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g2[i][j]); } puts(""); } puts("");
113 floyd();
114 if (equal(a, b)) {
115 puts("Yes");
116 } else {
117 puts("No");
120 return 0;